﻿using Sidvall.UI.Dialogs;
using Sidvall.UI.Uwp.Test.ViewModels;
using Sidvall.UI.Views;
using System.Threading.Tasks;

namespace Sidvall.UI.Uwp.Test.Views
{
    public sealed partial class Page1View : IViewModelProvider
    {
        #region Public Members

        public new Page1ViewModel ViewModel
        {
            get
            {
                return (Page1ViewModel)base.ViewModel;
            }
            set
            {
                base.ViewModel = value;
            }
        }

        Sidvall.UI.ViewModels.IViewModel IViewModelProvider.ViewModel
        {
            get
            {
                return this.ViewModel;
            }
        }

        #endregion
        #region Events

        private async void testButton1_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            using (var busyManager = new Sidvall.Data.BusyManager(this.ViewModel))
            {
                try
                {
                    var id = await Sidvall.SystemContext.Current.PackageManager.GetVersionAsync();
                    await Task.Delay(2000);
                }
                catch (System.Exception ex)
                {
                    await Sidvall.UI.SystemContext.Current.DialogManager.ShowErrorMessageAsync(ex);
                }
            }
        }
        private async void dialogButton1_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            using (var busyManager = new Sidvall.Data.BusyManager(this.ViewModel))
            {
                try
                {
                    var dialogContext = ProgressDialogContext.NewProgressDialogContext("Testing...");
                    dialogContext.Tasks.Add(new Sidvall.Tasks.DelayTask(5000));
                    var item = await Sidvall.UI.SystemContext.Current.DialogManager.ShowProgressDialogAsync(dialogContext);
                }
                catch (System.Exception ex)
                {
                    await Sidvall.UI.SystemContext.Current.DialogManager.ShowErrorMessageAsync(ex);
                }
            }
        }
        private async void dialogButton2_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            using (var busyManager = new Sidvall.Data.BusyManager(this.ViewModel))
            {
                try
                {
                    var response = await Sidvall.UI.SystemContext.Current.DialogManager.LogOnAsync("https://www.ebvd.org/SecurityManager/core/connect/authorize",
                        "bmiclient",
                        "code id_token token",
                        "openid profile email phone offline_access",
                        "https://www.ebvd.org/BMI/",
                        Sidvall.Security.TwoFactorProvider.None,
                        null,
                        "https://www.ebvd.org/SecurityManager/core/connect/endsession",
                        null,
                        "https://www.ebvd.org/SecurityManager/core/connect/token",
                        "client secret");
                    //var item = await Sidvall.UI.SystemContext.Current.DialogManager.LogOnAsync.OpenFolderAsync(UI.Dialogs.SpecialFolder.Desktop, null, false);
                }
                catch (System.Exception ex)
                {
                    await Sidvall.UI.SystemContext.Current.DialogManager.ShowErrorMessageAsync(ex);
                }
            }
        }
        private async void dialogButton3_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            using (var busyManager = new Sidvall.Data.BusyManager(this.ViewModel))
            {
                try
                {
                    var result = await Sidvall.UI.SystemContext.Current.DialogManager.ShowYesNoMessageAsync("test", @"kjsdhfshfeoiihsf 
sdföls sdifpsig prige dsa fsduf
wrfguprewoguouewro ruerugoerug reugeurgp se ljwejöwaeoi uöoaw uöoauw ögauwöuawögu
 ewraugpou guug u4  4gu409uh h34
sdföls sdifpsig prige dsa fsduf
wrfguprewoguouewro ruerugoerug reugeurgp se ljwejöwaeoi uöoaw uöoauw ögauwöuawögu
 ewraugpou guug u4  4gu409uh h34
sdföls sdifpsig prige dsa fsduf
wrfguprewoguouewro ruerugoerug reugeurgp se ljwejöwaeoi uöoaw uöoauw ögauwöuawögu
 ewraugpou guug u4  4gu409uh h34
sdföls sdifpsig prige dsa fsduf
wrfguprewoguouewro ruerugoerug reugeurgp se ljwejöwaeoi uöoaw uöoauw ögauwöuawögu
 ewraugpou guug u4  4gu409uh h34
 up4up93 uy", MessageType.Question, false);
                    if (result.AnswerIsYes)
                        await Sidvall.UI.SystemContext.Current.DialogManager.ShowMessageAsync("Answer", "YES", MessageType.Information);
                    else
                        await Sidvall.UI.SystemContext.Current.DialogManager.ShowMessageAsync("Answer", "NO", MessageType.Information);
                }
                catch (System.Exception ex)
                {
                    await Sidvall.UI.SystemContext.Current.DialogManager.ShowErrorMessageAsync(ex);
                }
            }
        }

        #endregion
        #region Constructors

        public Page1View()
        {
            this.InitializeComponent();
        }

        #endregion
    }
}
